#pragma once

#include <base/macro/aeval.h>

#define SEP_COMMA			,
#define SEP_SEMICON			;
#define __ETY

#define __MAP_POP0(decor, sep, f, x,...) \
	f decor (x) __VA_OPT__(sep DEFER(__MAP_POP1)(decor, sep, f, __VA_ARGS__))
#define __MAP_POP1(decor, sep, f, x,...) \
	f decor (x) __VA_OPT__(sep DEFER(__MAP_POP0)(decor, sep, f, __VA_ARGS__))

#define __MAP_POP0C(decor, f, x,...) \
	f decor (x) __VA_OPT__(, DEFER(__MAP_POP1C)(decor, f, __VA_ARGS__))
#define __MAP_POP1C(decor, f, x,...) \
	f decor (x) __VA_OPT__(, DEFER(__MAP_POP0C)(decor, f, __VA_ARGS__))


#define __MAP_POPL(sep, f, ...)		__MAP_POP0(__UNMLIST, sep, f, __VA_ARGS__)
#define __MAP_POP(sep, f, ...)		__MAP_POP0(__ETY, sep, f, __VA_ARGS__)

#define __MAPL(sep, f, ...)		EVAL(__MAP_POPL(sep, f, __VA_ARGS__))
#define __MAP(sep, f,  ...)		EVAL(__MAP_POP(sep, f, __VA_ARGS__))

/* candy */
#define MAP(f, ...)			__MAP(__ETY, f, __VA_ARGS__)
#define MAPC(f, ...)			EVAL(__MAP_POP0C(__ETY, f, __VA_ARGS__)) /*__MAP(SEP_COMMA, f,  __VA_ARGS__)*/
#define MAPS(f, ...)			__MAP(SEP_SEMICON, f, __VA_ARGS__)

#define MAPL(f, ...)			__MAPL(__ETY, f, __VA_ARGS__)
#define MAPLC(f, ...)			__MAPL(SEP_COMMA, f, __VA_ARGS__)
#define MAPLS(f, ...)			__MAPL(SEP_SEMICON, f, __VA_ARGS__)


